//GUI.cpp - realizacja funkcji z pliku GUI.h

#include <string>

#include <stdio.h>
#include <stdlib.h>
#include <Pt.h>
#include <iostream>
#include "GUI.h"
#define MAXIMUMLEVEL 10
#define MINIMUMLEVEL 1
#define DEFAULTVALUE 5


using namespace std;

/*
konstruktor klasy GUI <> destruktor zostawiamy domyslny, bo brak dynamoalokacji
*/

GUI::GUI()
	{
//utworzenie okna

	window = PtCreateWidget(PtWindow, Pt_NO_PARENT, 0, NULL);


	// wskazniki na funkcje zgodnie z helpem
	int (*airport_event) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=&push_button_airport;
	int (*airplane_event) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=&push_button_airplane;
	int (*airport_weather) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=&push_button_weather;
	int (*airplane_create) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=&push_button_create_airplane;
	int (*airplane_delete_event) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=&push_button_airplane_delete_event;
	int (*airport_delete_event) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=&push_button_airport_delete_event;
	int (*delete_weather) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=&push_button_delete_weather;
	int (*actualize) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=&push_button_actualize;
	
	// nawet nalezy
	PtCallback_t callbacks[]= {{airport_event, NULL}};
	PtCallback_t callbacksairplane[]= {{airplane_event, NULL}};
	PtCallback_t callbacksweather[]= {{airport_weather, NULL}};
	PtCallback_t callbackcreateairplane[]= {{airplane_create, NULL}};
	PtCallback_t callbackdeleteairplaneevent[]= {{airplane_delete_event, NULL}};
	PtCallback_t callbackdeleteweather[]= {{delete_weather, NULL}};
	PtCallback_t callbackdeleteairportevent[]= {{airport_delete_event, NULL}};
	PtCallback_t callbackactualize[]= {{actualize, NULL}};
	//utworzenie glownych przyciskow



	// obsluga lotniska
	
	//tworzy awarie na lotnisku
	
	PhPoint_t posa = {230, 500};
	PtSetArg( &arg_a[0], Pt_ARG_POS, &posa, 0 );
	PtSetArg( &arg_a[1], Pt_ARG_COLOR, Pg_BLACK, 0 );
	PtSetArg( &arg_a[2], Pt_ARG_TEXT_STRING, "AWARIA NA LOTNISKU", 0 );
	PtSetArg(&arg_a[3], Pt_CB_ACTIVATE, callbacks,
     sizeof(callbacks)/sizeof(callbacks[0]));
	przycisk_lotnisko = PtCreateWidget(PtButton, window, 4, arg_a);
  
  	// usuwa awarie na lotnisku
  	
    	PhPoint_t posc2 = { 220, 540};
	PtSetArg( &arg_c2[0], Pt_ARG_POS, &posc2, 0 );
	PtSetArg( &arg_c2[1], Pt_ARG_COLOR, Pg_BLACK, 0 );
	PtSetArg( &arg_c2[2], Pt_ARG_TEXT_STRING, "USUN AWARIE LOTNISKA", 0 );
	PtSetArg(&arg_c2[3], Pt_CB_ACTIVATE, callbackdeleteairportevent,
        sizeof(callbackdeleteairportevent)/sizeof(callbackdeleteairportevent[0]));	
	przycisk_samolot_awaria_stop = PtCreateWidget(PtButton, window, 4, arg_c2);
	
 
	//dodaje pogode do lotniska
	
  	PhPoint_t posb = { 430, 500};
	PtSetArg( &arg_b[0], Pt_ARG_POS, &posb, 0 );
	PtSetArg( &arg_b[1], Pt_ARG_COLOR, Pg_BLACK, 0 );
	PtSetArg( &arg_b[2], Pt_ARG_TEXT_STRING, "DODAJ POGODE", 0 );
	PtSetArg( &arg_b[3], Pt_CB_ACTIVATE, callbacksweather,
 	    sizeof(callbacks)/sizeof(callbacksweather[0]));
	przycisk_pogoda_dodaj = PtCreateWidget(PtButton, window, 4, arg_b);

	// usuwa pogode
	
	PhPoint_t posb1 = { 430, 540};
	PtSetArg( &arg_b1[0], Pt_ARG_POS, &posb1, 0 );
	PtSetArg( &arg_b1[1], Pt_ARG_COLOR, Pg_BLACK, 0 );
	PtSetArg( &arg_b1[2], Pt_ARG_TEXT_STRING, "USUN POGODE", 0 );
	PtSetArg(&arg_b1[3], Pt_CB_ACTIVATE, callbackdeleteweather,
        sizeof(callbackdeleteweather)/sizeof(callbackdeleteweather[0]));	
	przycisk_pogoda_usun = PtCreateWidget(PtButton, window, 4, arg_b1);


	//obsluga samolotu
	
	//otwiera okno tworzenia samolotu
	
	PhPoint_t posa1 = {650, 500 };
	PtSetArg( &arg_a1[0], Pt_ARG_POS, &posa1, 0 );
	PtSetArg( &arg_a1[1], Pt_ARG_COLOR, Pg_BLACK, 0 );
	PtSetArg( &arg_a1[2], Pt_ARG_TEXT_STRING, "UTWORZ SAMOLOT", 0 );
	PtSetArg(&arg_a1[3], Pt_CB_ACTIVATE, callbackcreateairplane,
        sizeof(callbackcreateairplane)/sizeof(callbackcreateairplane[0]));	
	przycisk_lotnisko_awaria_start = PtCreateWidget(PtButton, window, 4, arg_a1);
 
  	// dodaje awarie do samolotu
  	
	PhPoint_t posc = { 860, 500 };
	PtSetArg( &arg_c[0], Pt_ARG_POS, &posc, 0 );
	PtSetArg( &arg_c[1], Pt_ARG_COLOR, Pg_BLACK, 0 );
	PtSetArg( &arg_c[2], Pt_ARG_TEXT_STRING, "AWARIA SAMOLOTU", 0 );
	PtSetArg(&arg_c[3], Pt_CB_ACTIVATE, callbacksairplane,
        sizeof(callbacksairplane)/sizeof(callbacksairplane[0]));
	przycisk_samolot = PtCreateWidget(PtButton, window, 4, arg_c);
	
	// usuwa awarie samolotu
 
  	PhPoint_t posa2 = {850, 540};
	PtSetArg( &arg_a2[0], Pt_ARG_POS, &posa2, 0 );
	PtSetArg( &arg_a2[1], Pt_ARG_COLOR, Pg_BLACK, 0 );
	PtSetArg( &arg_a2[2], Pt_ARG_TEXT_STRING, "USUN AWARIE SAMOLOTU", 0 );
	PtSetArg(&arg_a2[3], Pt_CB_ACTIVATE, callbackdeleteairplaneevent,
        sizeof(callbackdeleteairplaneevent)/sizeof(callbackdeleteairplaneevent[0]));	
	przycisk_samolot_awaria_stop = PtCreateWidget(PtButton, window, 4, arg_a2);


/*	PhPoint_t posc1 = { 450, 600 };
	PtSetArg( &arg_c1[0], Pt_ARG_POS, &posc1, 0 );
	PtSetArg( &arg_c1[1], Pt_ARG_COLOR, Pg_BLACK, 0 );
	PtSetArg( &arg_c1[2], Pt_ARG_TEXT_STRING, "AKTUALIZUJ SAMOLOT", 0 );
	przycisk_samolot_awaria_start = PtCreateWidget(PtButton, window, 3, arg_c1);
	PtAddCallback(przycisk_samolot_awaria_start, Pt_CB_ACTIVATE, push_button_actualize, list_airplane);
*/
/*
	PhPoint_t posc3 = { 800, 700};
	PtSetArg( &arg_c3[0], Pt_ARG_POS, &posc3, 0 );
	PtSetArg( &arg_c3[1], Pt_ARG_COLOR, Pg_BLACK, 0 );
	PtSetArg( &arg_c3[2], Pt_ARG_TEXT_STRING, "UTWORZ", 0 );
	//PtSetArg(&arg_a2[3], Pt_CB_ACTIVATE, callbacks_b,  0);
	przycisk_samolot_tworz = PtCreateWidget(PtButton, window, 4, arg_c3);
*/

	// lista lotnisk
	PhDim_t dim;
	PhPoint_t pol;
	
	PtArg_t arg_list_airport[4];	
	pol.x = 1;
	pol.y = 50;
	dim.h = 400;
	dim.w = 200;
	PtSetArg(&arg_list_airport[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_list_airport[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_list_airport[2], Pt_ARG_SELECTION_MODE,Pt_SINGLE_MODE, 0);
	list_airport = PtCreateWidget(PtList, window,4 , arg_list_airport);
	PtArg_t arg_label_airport[4];
	pol.y-=20;
	dim.h=20;
	PtSetArg(&arg_label_airport[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_label_airport[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_label_airport[2], Pt_ARG_TEXT_STRING,"Lotnisko:",0);
	PtWidget_t *label_airport = PtCreateWidget(PtLabel, window,4 , arg_label_airport);
	
	// lista zdarzen na lotniskach
	
     PtArg_t arg_list_airport_events[4];	
	pol.x+= 203;
 
	pol.y = 50;
	dim.h = 400;
	dim.w = 200;
	PtSetArg(&arg_list_airport_events[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_list_airport_events[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_list_airport_events[2], Pt_ARG_SELECTION_MODE,Pt_SINGLE_MODE, 0);
	list_airport_events = PtCreateWidget(PtList, window,4 , arg_list_airport_events);
	PtArg_t arg_label_airport_events[4];
	pol.y -= 20;
	dim.h=20;
	PtSetArg(&arg_label_airport_events[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_label_airport_events[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_label_airport_events[2], Pt_ARG_TEXT_STRING,"Zdarzenia na lotnisku:",0);
	PtWidget_t *label_airport_events = PtCreateWidget(PtLabel, window,4 , arg_label_airport_events);
    
	//lista pogody na lotniskach
	
	PtArg_t arg_list_airport_weather[4];
	pol.x+= 203;
	pol.y = 50;
	dim.h = 400;
	dim.w = 180;
	PtSetArg(&arg_list_airport_weather[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_list_airport_weather[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_list_airport_weather[2], Pt_ARG_SELECTION_MODE,Pt_SINGLE_MODE, 0);
	list_airport_weather = PtCreateWidget(PtList, window,4 , arg_list_airport_weather);
	PtArg_t arg_label_airport_weather[4];
	pol.y-=20;
	dim.h=20;
	PtSetArg(&arg_label_airport_weather[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_label_airport_weather[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_label_airport_weather[2], Pt_ARG_TEXT_STRING,"Pogoda na lotnisku:",0);
	PtWidget_t *label_airport_weather= PtCreateWidget(PtLabel, window,4 , arg_label_airport_weather);

	// samolot
	PtArg_t arg_list_airplane[4];	
	pol.x += 206;
	pol.y = 50;
	dim.h = 400;
	dim.w = 200;
	PtSetArg(&arg_list_airplane[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_list_airplane[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_list_airplane[2], Pt_ARG_SELECTION_MODE,Pt_SINGLE_MODE, 0);
	list_airplane = PtCreateWidget(PtList, window,4 , arg_list_airplane);
	PtArg_t arg_label_airplane[4];
	pol.y-=20;
	dim.h=20;
	PtSetArg(&arg_label_airplane[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_label_airplane[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_label_airplane[2], Pt_ARG_TEXT_STRING,"Samolot:",0);
	PtWidget_t *label_airplane = PtCreateWidget(PtLabel, window,4 , arg_label_airplane);
	
	// lista zdarzen w samolocie
	
     PtArg_t arg_list_airplane_events[4];
	pol.x += 203;
	pol.y = 50;
	dim.h = 400;
	dim.w = 200;
	PtSetArg(&arg_list_airplane_events[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_list_airplane_events[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_list_airplane_events[2], Pt_ARG_SELECTION_MODE,Pt_SINGLE_MODE, 0);
	list_airplane_events = PtCreateWidget(PtList, window,4 , arg_list_airplane_events);
	PtArg_t arg_label_airplane_events[4];
	pol.y -= 20;
	dim.h=20;
	PtSetArg(&arg_label_airplane_events[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_label_airplane_events[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_label_airplane_events[2], Pt_ARG_TEXT_STRING,"Zdarzenia w samolocie:",0);
	PtWidget_t *label_airplane_events = PtCreateWidget(PtLabel, window,4 , arg_label_airplane_events);
	
		
	//samolot
	int (*fs) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=&push_list_airplane_main_window;
	PtAddCallback(list_airplane, Pt_CB_SELECTION, fs, list_airplane_events);
		
	int (*fs2) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=&push_list_airplane_events;
	PtAddCallback(list_airplane_events, Pt_CB_SELECTION, fs2, list_airplane);
	
	
	// lotnisko
	
int (*f) (PtWidget_t *a, void *b,PtCallbackInfo_t *c)=&push_list_airport;
	int (*fa) (PtWidget_t *a, void *b,PtCallbackInfo_t *c)=&push_list_airport_weather;
	
	PtAddCallback(list_airport, Pt_CB_SELECTION, f, list_airport_events);
	PtAddCallback(list_airport, Pt_CB_SELECTION, fa, list_airport_weather);
	
	int (*f2) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=&push_list_events;
	PtAddCallback(list_airport_events, Pt_CB_SELECTION, f2, list_airport_weather);
	
	int (*f3) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=&push_list_weather;	
	PtAddCallback(list_airport_weather, Pt_CB_SELECTION, f3, list_airport_events);
	
	
	fill_list(list_airport);
	fill_list(list_airplane);
	//fill_list(list_airport_weather);
	
	//tmp
	//PtArg_t arg_list_airplane[4];	
	pol.x = 630;
	pol.y = 470;
	dim.h = 25;
	dim.w = 80;
	PtSetArg(&arg_list_airplane[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_list_airplane[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_list_airplane[2], Pt_ARG_SELECTION_MODE,Pt_SINGLE_MODE, 0);
	list_airplane_act = PtCreateWidget(PtList, window,4 , arg_list_airplane);
	int (*fsa) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=&push_list_airplane_act;
	PtAddCallback(list_airplane_act, Pt_CB_SELECTION, fsa, list_airplane);
	const char * cs[]={"aktualizuj"};
	PtListAddItems((PtWidget_t *)  list_airplane_act, cs, 1, 0);
	
	
	PtRealizeWidget(window);	
	}
	
int fill_airplane_list(PtWidget_t *list_airplane);










// wypelnia liste samolotow i lotnisk
int GUI::fill_list(PtWidget_t* list)
{
		const char * constlist[50];
		int i=0;
		int k =23;
		//char k1=(char)k;
		//string ds="ddd";
		//string sa=ds+=k;
		//string dd=sa+="haha";
		//cout << dd<<endl;
		if (list == list_airport) {
			vector<lotnisko> tmp = Zdarzenia::getInstance().get_lotniska();
			for(vector<lotnisko>::iterator it=tmp.begin(); it < tmp.end(); it++) {
				constlist[i++] = (it->nazwa+=k).c_str();
			}
		}
	
		else if (list == list_airplane){//// list_new_airplanes) {
			vector<samolot_polozenie> tmp = Zdarzenia::getInstance().get_aktywne_samoloty();
			for(vector<samolot_polozenie>::iterator it=tmp.begin(); it < tmp.end(); it++) {
				constlist[i++] = ((it->nazwa_samolotu)).c_str();
			}
		}
		
		PtListAddItems(list, constlist, i, 0);
		/*else if (list == list_airplane){//// list_new_airplanes) {
			cout << "dobrze"<<endl;
			vector<samolot> tmp = Zdarzenia::getInstance().get_samoloty();
			for(vector<samolot>::iterator it=tmp.begin(); it < tmp.end(); it++) {
				constlist[i++] = (it->nazwa).c_str();
			}
		}
		PtListAddItems(list, constlist, i, 0);
*/
}



// oblsuga listy lotnisk - wypelnia liste awarii
int GUI::push_list_airport(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{
	PtListDeleteAllItems((PtWidget_t *) data);
	Zdarzenia::getInstance().put_event("null");
	cout << Zdarzenia::getInstance().get_event()<<endl;
	Zdarzenia::getInstance().put_airport_from(((PtListCallback_t *)(cbinfo->cbdata))->item);
	const char* constlist[50];
	int i = 0;

	// ma tak byc
	lista_awarii tmp = Zdarzenia::getInstance().get_lotnisko_awarie(((PtListCallback_t *)(cbinfo->cbdata))->item);
	for(vector<zdarzenie>::iterator it=tmp.awaria.begin(); it < tmp.awaria.end(); it++) {
		constlist[i++] = (it->nazwa).c_str();
	}
	
	//koniec

	
	//tymczasowe
//	constlist[i++]="strajk";
//	constlist[i++]="bomba";
	//endof tymczasowe
	
	PtListAddItems((PtWidget_t *)  data, constlist, i, 0);
}

// oblsuga listy lotnisk - wypelnia liste pogody
int GUI::push_list_airport_weather(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{
	PtListDeleteAllItems((PtWidget_t *) data);
	Zdarzenia::getInstance().put_weather("null");
	cout << Zdarzenia::getInstance().get_weather()<<endl;
	Zdarzenia::getInstance().put_airport_from(((PtListCallback_t *)(cbinfo->cbdata))->item);	
	//cout << "lotnisko od " << Zdarzenia::getInstance().get_airport_from()<<endl;
	const char* constlist[50];
	int i = 0;
	lista_awarii tmp = Zdarzenia::getInstance().get_lotnisko_pogoda(((PtListCallback_t *)(cbinfo->cbdata))->item);
	for(vector<zdarzenie>::iterator it=tmp.awaria.begin(); it < tmp.awaria.end(); it++) {
		constlist[i++] = (it->nazwa).c_str();
	}
//	constlist[i++]="tornado";
//	constlist[i++]="snieg";
	PtListAddItems((PtWidget_t *)  data, constlist, i, 0);
}

//oblsuga listy zdarzen
int GUI::push_list_events(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{
	Zdarzenia::getInstance().put_event(((PtListCallback_t *)(cbinfo->cbdata))->item);
	cout << Zdarzenia::getInstance().get_event()<< endl;
}

//oblsuga listy pogody
int GUI::push_list_weather(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{
	Zdarzenia::getInstance().put_weather(((PtListCallback_t *)(cbinfo->cbdata))->item);
	cout << Zdarzenia::getInstance().get_weather()<< endl;
}

//oblsuga listy samolot
int GUI::push_list_airplane_main_window(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{
	PtListDeleteAllItems((PtWidget_t *) data);
	Zdarzenia::getInstance().put_airplane_event("null");
	cout << Zdarzenia::getInstance().get_airplane_event()<<endl;
	
	int id=-1;
	vector<samolot_polozenie> tmp2 = Zdarzenia::getInstance().get_aktywne_samoloty();
	for(vector<samolot_polozenie>::iterator it=tmp2.begin(); it < tmp2.end(); it++) {
		    char k1[20];
    		    const char *k2;
    	         string k3, tmp2;
              k2 = itoa(it->id_samolotu,k1,10);
              tmp2 = k2;
         	    k3=tmp2 + (it->nazwa_samolotu);
              k2=k3.c_str();
		    if (!strcmp(((PtListCallback_t *)(cbinfo->cbdata))->item,k2))
		    {
			   id = it->id_samolotu;
			   cout << "id samolotu: "<< it->id_samolotu << endl;
		 	   break;
		    }
	}
	
	Zdarzenia::getInstance().put_airplane_id(id);
	cout<< "id samolotu " << Zdarzenia::getInstance().get_airplane_id()<<endl;
	
	const char* constlist[50];
	int i = 0;
	lista_awarii tmp = Zdarzenia::getInstance().get_samolot_awarie(((PtListCallback_t *)(cbinfo->cbdata))->item);
	for(vector<zdarzenie>::iterator it=tmp.awaria.begin(); it != tmp.awaria.end(); it++) {
		constlist[i++] = (it->nazwa).c_str();
	}
	PtListAddItems((PtWidget_t *)  data, constlist, i, 0);
}

//obsluga listy awarii w samolocie
int GUI::push_list_airplane_events(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{
	Zdarzenia::getInstance().put_airplane_event(((PtListCallback_t *)(cbinfo->cbdata))->item);
	cout << Zdarzenia::getInstance().get_airplane_event()<<endl;
}

//oblsuga przycisku usuwania zdarzenia w samolocie
int GUI::push_button_airplane_delete_event(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{
	cout << "usuwam awarie samolotu"<<endl;
	Zdarzenia::getInstance().usun_awarie_samolotu();
}

// obsluga przycisku usuwania awarii na lotnisku
int GUI::push_button_airport_delete_event(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{
	cout << "usuwam awarie lotniska"<<endl;
	Zdarzenia::getInstance().usun_awarie_lotniska();
}

//obsluga przycisku usuawania pogody
int GUI::push_button_delete_weather(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{
	cout << "usuwam pogode" << endl;
	Zdarzenia::getInstance().usun_awarie_pogody();
}




// koniec obslugi okna glownego




// obsluga okna tworzenia samolotu



// oblsuga przycisku znajdujacego sie na oknie tworzenia samolotu
int GUI::push_button_create_airplane_window(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{
	if (Zdarzenia::getInstance().get_airplane_id() == -1)	
		Zdarzenia::getInstance().wyslij_samolot();
	else
		Zdarzenia::getInstance().wyslij_ponownie_samolot();
}

//obsluga listy lotnisk startowych
int GUI::push_list_airport_from(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{	
	PtListDeleteAllItems( (PtWidget_t *)  data);
	Zdarzenia::getInstance().put_airplane("null");
	cout << Zdarzenia::getInstance().get_airplane()<<endl;
	Zdarzenia::getInstance().put_airport_from(((PtListCallback_t *)(cbinfo->cbdata))->item);	
	cout<< "lotnisko od " << Zdarzenia::getInstance().get_airport_from()<<endl;
	const char* constlist[50];
	int i = 0;
	vector<samolot> tmp = Zdarzenia::getInstance().get_samoloty();
	for(vector<samolot>::iterator it=tmp.begin(); it < tmp.end(); it++) {
		constlist[i++] = (it->nazwa).c_str();
	}
	
	/*vector<samolot_polozenie> tmp2 = Zdarzenia::getInstance().samoloty_na_lotnisku();
	for(vector<samolot_polozenie>::iterator it2=tmp2.begin();it2<tmp2.end();it2++) {
		constlist[i++] = (it2->nazwa_samolotu).c_str();
	}*/
	PtListAddItems((PtWidget_t *)  data, constlist, i, 0);
}

// druga lista
int GUI::push_list_airport_from_existing_airplane(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{	
	PtListDeleteAllItems( (PtWidget_t *)  data);
	Zdarzenia::getInstance().put_airplane("null");
	Zdarzenia::getInstance().put_airplane_id(-1);
	cout << Zdarzenia::getInstance().get_airplane()<<endl;
	Zdarzenia::getInstance().put_airport_from(((PtListCallback_t *)(cbinfo->cbdata))->item);	
	cout<< "lotnisko od " << Zdarzenia::getInstance().get_airport_from()<<endl;

	const char* constlist[50];
	int i = 0;

	vector<samolot_polozenie> tmp2 = Zdarzenia::getInstance().samoloty_na_lotnisku();
	for(vector<samolot_polozenie>::iterator it2=tmp2.begin();it2<tmp2.end();it2++) {
		constlist[i++] = (it2->nazwa_samolotu).c_str();
	}
//	constlist[i++]="awionetka";
//	constlist[i++]="jumbojet";
	PtListAddItems((PtWidget_t *)  data, constlist, i, 0);
}


//obsluga listy samolot
int GUI::push_list_airplane(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{	
	PtListDeleteAllItems( (PtWidget_t *)  data);
	Zdarzenia::getInstance().put_airplane_id(-1);	
	Zdarzenia::getInstance().put_airport_to("null");
	cout << Zdarzenia::getInstance().get_airport_to()<<endl;
	Zdarzenia::getInstance().put_airplane(((PtListCallback_t *)(cbinfo->cbdata))->item);	
	cout<< "samolot " << Zdarzenia::getInstance().get_airplane()<<endl;
	const char* constlist[50];
	int i = 0;
	vector<lotnisko> tmp = Zdarzenia::getInstance().lotniska_w_zasiegu();
	for(vector<lotnisko>::iterator it=tmp.begin(); it < tmp.end(); it++) {
		constlist[i++] = (it->nazwa).c_str();
	}
	PtListAddItems((PtWidget_t *)  data, constlist, i, 0);
}

//obsluga listy lotnisk docelowych
int GUI::push_list_airport_to(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{
	Zdarzenia::getInstance().put_airport_to(((PtListCallback_t *)(cbinfo->cbdata))->item);	
	cout<< "lotnisko do " << Zdarzenia::getInstance().get_airport_to()<<endl;
}

//oblsuga przycisku tworzenia samolotu
int GUI::push_button_create_airplane(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{
	PtWidget_t *airplane = PtCreateWidget(PtWindow, NULL, 0, NULL);
		
	
	int (*airplane_create_window) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=&push_button_create_airplane_window;
	PtCallback_t callbackcreateairplane[]= {{airplane_create_window, NULL}};
	
	PhPoint_t posb1 = { 300, 600};
	PtArg_t arg_bs1[4];	
	PtSetArg( &arg_bs1[0], Pt_ARG_POS, &posb1, 0 );
	PtSetArg( &arg_bs1[1], Pt_ARG_COLOR, Pg_BLACK, 0 );
	PtSetArg( &arg_bs1[2], Pt_ARG_TEXT_STRING, "UTWORZ", 0 );
	PtSetArg(&arg_bs1[3], Pt_CB_ACTIVATE, callbackcreateairplane,
 	      sizeof(callbackcreateairplane)/sizeof(callbackcreateairplane[0]));	
	PtWidget_t *but = PtCreateWidget(PtButton, airplane,4,arg_bs1);	
	
	PhDim_t dim;
	PhPoint_t pol;
	
	PtArg_t arg_list_airport[4];	
	pol.x = 1;
	pol.y = 50;
	dim.h = 400;
	dim.w = 200;
	PtSetArg(&arg_list_airport[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_list_airport[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_list_airport[2], Pt_ARG_SELECTION_MODE,Pt_SINGLE_MODE, 0);
	PtWidget_t *list_airport = PtCreateWidget(PtList, airplane,4 , arg_list_airport);
	PtArg_t arg_label_airport[4];
	pol.y-=20;
	dim.h=20;
	PtSetArg(&arg_label_airport[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_label_airport[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_label_airport[2], Pt_ARG_TEXT_STRING,"Lotnisko startowe",0);
	PtWidget_t *label_airport = PtCreateWidget(PtLabel, airplane,4 , arg_label_airport);
	
	// lista zdarzen na lotniskach
	
     PtArg_t arg_list_airport_events[4];	
	pol.x+= 203;
	pol.y = 50;
	dim.h = 400;
	dim.w = 200;
	PtSetArg(&arg_list_airport_events[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_list_airport_events[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_list_airport_events[2], Pt_ARG_SELECTION_MODE,Pt_SINGLE_MODE, 0);
	PtWidget_t *list_airport_events = PtCreateWidget(PtList, airplane,4 , arg_list_airport_events);
	PtArg_t arg_label_airport_events[4];
	pol.y -= 20;
	dim.h=20;
	PtSetArg(&arg_label_airport_events[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_label_airport_events[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_label_airport_events[2], Pt_ARG_TEXT_STRING,"Nowy samolot",0);
	PtWidget_t *label_airport_events = PtCreateWidget(PtLabel, airplane,4 , arg_label_airport_events);
    
    
    
    
    
    // stare samoloty
    
    
     //PtArg_t arg_list_airport_events[4];	
	pol.x+= 203;
	pol.y = 50;
	dim.h = 400;
	dim.w = 200;
	PtSetArg(&arg_list_airport_events[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_list_airport_events[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_list_airport_events[2], Pt_ARG_SELECTION_MODE,Pt_SINGLE_MODE, 0);
	PtWidget_t *list_airplane_reuse = PtCreateWidget(PtList, airplane,4 , arg_list_airport_events);
	//PtArg_t arg_label_airport_events[4];
	pol.y -= 20;
	dim.h=20;
	PtSetArg(&arg_label_airport_events[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_label_airport_events[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_label_airport_events[2], Pt_ARG_TEXT_STRING,"Samolot w hangarze",0);
	PtWidget_t *label_airport_events2 = PtCreateWidget(PtLabel, airplane,4 , arg_label_airport_events);
   
    	int (*fold) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=&push_list_airport_from_existing_airplane;
	PtAddCallback(list_airport, Pt_CB_SELECTION,fold, list_airplane_reuse);
	

    // koniec starych samolotow
    
	//lista pogody na lotniskach
	
	PtArg_t arg_list_airport_weather[4];
	pol.x+= 203;
	pol.y = 50;
	dim.h = 400;
	dim.w = 180;
	PtSetArg(&arg_list_airport_weather[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_list_airport_weather[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_list_airport_weather[2], Pt_ARG_SELECTION_MODE,Pt_SINGLE_MODE, 0);
	PtWidget_t *list_airport_weather = PtCreateWidget(PtList, airplane,4 , arg_list_airport_weather);
	PtArg_t arg_label_airport_weather[4];
	pol.y-=20;
	dim.h=20;
	PtSetArg(&arg_label_airport_weather[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_label_airport_weather[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_label_airport_weather[2], Pt_ARG_TEXT_STRING,"Lotnisko docelowe",0);
	PtWidget_t *label_airport_weather= PtCreateWidget(PtLabel, airplane,4 , arg_label_airport_weather);
	
	int (*f) (PtWidget_t *a, void *b,PtCallbackInfo_t *c)=&push_list_airport_from;
	PtAddCallback(list_airport, Pt_CB_SELECTION,f, list_airport_events);
	
	int (*f2) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=&push_list_airplane;
	PtAddCallback(list_airport_events, Pt_CB_SELECTION,f2, list_airport_weather);
	
	int (*f3) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=&push_list_airport_to;	
	PtAddCallback(list_airport_weather, Pt_CB_SELECTION,f3, list_airport_events);
	
	
	int (*airplane_old) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=&push_list_airplane_old;
	PtAddCallback(list_airplane_reuse, Pt_CB_SELECTION,airplane_old, list_airport_weather);
	
	const char * constlist[50];
	int i=0;
	
	vector<lotnisko> tmp = Zdarzenia::getInstance().get_lotniska();
	for(vector<lotnisko>::iterator it=tmp.begin(); it < tmp.end(); it++) {
		constlist[i++] = (it->nazwa).c_str();
	}
	PtListAddItems(list_airport, constlist, i, 0);
	PtRealizeWidget(airplane);
}

int GUI::push_list_airplane_old(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{
	PtListDeleteAllItems( (PtWidget_t *)  data);
	cout << "stare samoloty" << endl;
	Zdarzenia::getInstance().put_airplane(((PtListCallback_t *)(cbinfo->cbdata))->item);
	cout << "samolot ponownie wysylany " <<Zdarzenia::getInstance().get_airplane() << endl;	
	int id=-1;
	
	vector<samolot_polozenie> tmp = Zdarzenia::getInstance().get_polozenie();
	for(vector<samolot_polozenie>::iterator it=tmp.begin(); it < tmp.end(); it++) {
		if (!strcmp(((PtListCallback_t *)(cbinfo->cbdata))->item,(it->nazwa_samolotu).c_str()))
		{ 
			id = it->id_samolotu;
			cout << "id samolotu: "<< it->id_samolotu << endl;
		 	break;
		}
	}
	
	Zdarzenia::getInstance().put_airplane_id(id);	
	cout<< "id samolotu " << Zdarzenia::getInstance().get_airplane_id()<<endl;
	
	const char* constlist[50];
	int i = 0;
	vector<lotnisko> tmp2 = Zdarzenia::getInstance().lotniska_w_zasiegu();
	for(vector<lotnisko>::iterator it=tmp2.begin(); it < tmp2.end(); it++) {
		constlist[i++] = (it->nazwa).c_str();
	}
	PtListAddItems((PtWidget_t *)  data, constlist, i, 0);
	
	
}


// koniec obslugi okna tworzenia lotnisk




// oblsuga okna dodawania awarii do lotniska




// obsluga przycisku dodawanie awarii lotniska
int GUI::push_button_airport(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{
	PtWidget_t *airport_event = PtCreateWidget(PtWindow, NULL, 0, NULL);
		
	
int (*airport_add_event) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=&push_button_airport_add_event;
	PtCallback_t callbackairportadd[]= {{airport_add_event, NULL}};
	
	PhPoint_t posb1 = { 300, 600};
	PtArg_t arg_bs1[4];	
	PtSetArg( &arg_bs1[0], Pt_ARG_POS, &posb1, 0 );
	PtSetArg( &arg_bs1[1], Pt_ARG_COLOR, Pg_BLACK, 0 );
	PtSetArg( &arg_bs1[2], Pt_ARG_TEXT_STRING, "DODAJ AWARIE", 0 );
	PtSetArg(&arg_bs1[3], Pt_CB_ACTIVATE, callbackairportadd,
 	      sizeof(callbackairportadd)/sizeof(callbackairportadd[0]));	
	PtWidget_t *but = PtCreateWidget(PtButton, airport_event, 4, arg_bs1);	
	
	PhDim_t dim;
	PhPoint_t pol;
	
	PtArg_t arg_list_airport[4];	
	pol.x = 1;
	pol.y = 50;
	dim.h = 400;
	dim.w = 200;
	PtSetArg(&arg_list_airport[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_list_airport[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_list_airport[2], Pt_ARG_SELECTION_MODE,Pt_SINGLE_MODE, 0);
	PtWidget_t *list_airport = PtCreateWidget(PtList, airport_event, 4, arg_list_airport);
	PtArg_t arg_label_airport[4];
	pol.y-=20;
	dim.h=20;
	PtSetArg(&arg_label_airport[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_label_airport[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_label_airport[2], Pt_ARG_TEXT_STRING,"Lotnisko",0);
	PtWidget_t *label_airport = PtCreateWidget(PtLabel, airport_event, 4, arg_label_airport);
	
	// lista zdarzen na lotniskach
	
     PtArg_t arg_list_airport_events[4];	
	pol.x+= 203;
	pol.y = 50;
	dim.h = 400;
	dim.w = 200;
	PtSetArg(&arg_list_airport_events[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_list_airport_events[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_list_airport_events[2], Pt_ARG_SELECTION_MODE,Pt_SINGLE_MODE, 0);
	PtWidget_t *list_airport_events = PtCreateWidget(PtList, airport_event, 4, arg_list_airport_events);
	PtArg_t arg_label_airport_events[4];
	pol.y -= 20;
	dim.h=20;
	PtSetArg(&arg_label_airport_events[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_label_airport_events[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_label_airport_events[2], Pt_ARG_TEXT_STRING,"AWARIA",0);
	PtWidget_t *label_airport_events = PtCreateWidget(PtLabel, airport_event, 4, arg_label_airport_events);
    
	int (*f) (PtWidget_t *a, void *b,PtCallbackInfo_t *c)=&push_list_airport_add_event_airport;
	PtAddCallback(list_airport, Pt_CB_SELECTION,f, list_airport_events);
	
	int (*f2) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=&push_list_airport_add_event_event;
	PtAddCallback(list_airport_events, Pt_CB_SELECTION, f2, list_airport);


	// obsluga wyboru poziomu awarii


	int (*level) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=&push_numeric_level;
	PtCallback_t callbacklevel[]= {{level, NULL}};

	pol.x =220;
	pol.y = 500;
	PtArg_t numeric_level[4];
	PtSetArg(&numeric_level[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&numeric_level[1], Pt_ARG_NUMERIC_MAX, MAXIMUMLEVEL,0);
	PtSetArg(&numeric_level[2], Pt_ARG_NUMERIC_MIN, MINIMUMLEVEL,0);	
	PtSetArg(&numeric_level[3], Pt_ARG_NUMERIC_VALUE, DEFAULTVALUE,0);
	PtSetArg(&numeric_level[4], Pt_CB_NUMERIC_CHANGED, callbacklevel,
		sizeof(callbacklevel)/sizeof(callbacklevel[0]));	
	
	PtWidget_t *numeric = PtCreateWidget(PtNumericInteger, airport_event, 5, numeric_level);
	
	Zdarzenia::getInstance().put_level(DEFAULTVALUE);	
	cout << "Ustawiono domyslny stopien na: " << Zdarzenia::getInstance().get_level() <<endl;
	
	PtArg_t arg_label_level[4];
	pol.x -= 100;
	pol.y += 5;
	dim.h=20;
	PtSetArg(&arg_label_level[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_label_level[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_label_level[2], Pt_ARG_TEXT_STRING,"Stopien awarii: ",0);
	PtWidget_t *label_level = PtCreateWidget(PtLabel, airport_event, 4, arg_label_level);
    
//	koniec obslugi wyboru poziomu awarii


	const char * constlist[50];
	int i=0;
	
	vector<lotnisko> tmp = Zdarzenia::getInstance().get_lotniska();
	for(vector<lotnisko>::iterator it=tmp.begin(); it < tmp.end(); it++) {
		constlist[i++] = (it->nazwa).c_str();
	}
	PtListAddItems(list_airport, constlist, i, 0);
	
	PtRealizeWidget(airport_event);
}

// oblsuga przycisku znajdujacego sie na oknie dodawania awarii lotniska
int GUI::push_button_airport_add_event(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{
		Zdarzenia::getInstance().dodaj_awarie_lotniska();
		cout << "dodaje awarie" <<endl;
		Zdarzenia::getInstance().put_event("null");
		cout << "awaria wyczyszczona "<<Zdarzenia::getInstance().get_event()<<endl;
		Zdarzenia::getInstance().put_airport_from("null");	
		cout<< "lotnisko wyczyszczone " << Zdarzenia::getInstance().get_airport_from()<<endl;
}

//obsluga listy lotnisko
int GUI::push_list_airport_add_event_airport(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{	
	PtListDeleteAllItems( (PtWidget_t *)  data);
	Zdarzenia::getInstance().put_event("null");
	cout << Zdarzenia::getInstance().get_event()<<endl;
	Zdarzenia::getInstance().put_airport_from(((PtListCallback_t *)(cbinfo->cbdata))->item);	
	cout<< "lotnisko " << Zdarzenia::getInstance().get_airport_from()<<endl;

	const char* constlist[50];
	int i = 0;
	//lista_awarii tmp = Zdarzenia::getInstance().get_samolot_awarie(((PtListCallback_t *)(cbinfo->cbdata))->item);

	//bedzie
	//	lista_awarii tmp = Zdarzenia::getInstance().get_lotnisko_mozliwe_awarie(((PtListCallback_t *)(cbinfo->cbdata))->item);
	//koniec
	
	vector<zdarzenie> zdarzenia = Zdarzenia::getInstance().mozliwe_awarie_lotnisko();	
	for(vector<zdarzenie>::iterator it=zdarzenia.begin(); it < zdarzenia.end(); it++) {
		constlist[i++] = (it->nazwa).c_str();
	}
	
	/*vector<zdarzenie> tmp = Zdarzenia::getInstance().get_awarie();
	for(vector<zdarzenie>::iterator it=tmp.begin(); it < tmp.end(); it++) {
		constlist[i++] = (it->nazwa).c_str();
	}*/
	
	//tymczasowe dopoki nie ma danych
//	constlist[i++]="atak terorystyczny";
//	constlist[i++]="pozar";
	//koniec tymczasowe
	
	PtListAddItems((PtWidget_t *)  data, constlist, i, 0);
}

//obsluga listy awarii
int GUI::push_list_airport_add_event_event(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{
	Zdarzenia::getInstance().put_event(((PtListCallback_t *)(cbinfo->cbdata))->item);	
	cout<< "awaria lotniska " << Zdarzenia::getInstance().get_event()<<endl;
}




// koniec obslugi okna dodawania awarii lotnisk




// oblsuga okna dodawania pogody do lotniska




// obsluga przycisku dodawanie awarii lotniska
//obsluga przycisku dodawania pogody
int GUI::push_button_weather(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{
	PtWidget_t *airport_weather = PtCreateWidget(PtWindow, NULL, 0, NULL);
		
	
int (*airport_add_event) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=&push_button_airport_add_weather;
	PtCallback_t callbackairportadd[]= {{airport_add_event, NULL}};
	
	PhPoint_t posb1 = { 300, 600};
	PtArg_t arg_bs1[4];	
	PtSetArg( &arg_bs1[0], Pt_ARG_POS, &posb1, 0 );
	PtSetArg( &arg_bs1[1], Pt_ARG_COLOR, Pg_BLACK, 0 );
	PtSetArg( &arg_bs1[2], Pt_ARG_TEXT_STRING, "DODAJ POGODE", 0 );
	PtSetArg(&arg_bs1[3], Pt_CB_ACTIVATE, callbackairportadd,
 	      sizeof(callbackairportadd)/sizeof(callbackairportadd[0]));	
	PtWidget_t *but = PtCreateWidget(PtButton, airport_weather, 4, arg_bs1);	
	
	PhDim_t dim;
	PhPoint_t pol;
	
	PtArg_t arg_list_airport[4];	
	pol.x = 1;
	pol.y = 50;
	dim.h = 400;
	dim.w = 200;
	PtSetArg(&arg_list_airport[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_list_airport[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_list_airport[2], Pt_ARG_SELECTION_MODE,Pt_SINGLE_MODE, 0);
	PtWidget_t *list_airport = PtCreateWidget(PtList, airport_weather, 4, arg_list_airport);
	PtArg_t arg_label_airport[4];
	pol.y-=20;
	dim.h=20;
	PtSetArg(&arg_label_airport[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_label_airport[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_label_airport[2], Pt_ARG_TEXT_STRING,"Lotnisko",0);
	PtWidget_t *label_airport = PtCreateWidget(PtLabel, airport_weather, 4, arg_label_airport);
	
	// lista zdarzen na lotniskach
	
     PtArg_t arg_list_airport_weather[4];	
	pol.x+= 203;
	pol.y = 50;
	dim.h = 400;
	dim.w = 200;
	PtSetArg(&arg_list_airport_weather[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_list_airport_weather[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_list_airport_weather[2], Pt_ARG_SELECTION_MODE,Pt_SINGLE_MODE, 0);
	PtWidget_t *list_airport_weather = PtCreateWidget(PtList, airport_weather, 4, arg_list_airport_weather);
	PtArg_t arg_label_airport_weather[4];
	pol.y -= 20;
	dim.h=20;
	PtSetArg(&arg_label_airport_weather[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_label_airport_weather[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_label_airport_weather[2], Pt_ARG_TEXT_STRING,"POGODA",0);
	PtWidget_t *label_airport_weather = PtCreateWidget(PtLabel, airport_weather, 4, arg_label_airport_weather);
    
	int (*f) (PtWidget_t *a, void *b,PtCallbackInfo_t *c)=&push_list_airport_add_weather_airport;
	PtAddCallback(list_airport, Pt_CB_SELECTION,f, list_airport_weather);
	
	int (*f2) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=&push_list_airport_add_weather_weather;
	PtAddCallback(list_airport_weather, Pt_CB_SELECTION, f2, list_airport);


	// obsluga wyboru poziomu awarii


	int (*level) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=&push_numeric_level;
	PtCallback_t callbacklevel[]= {{level, NULL}};

	pol.x =220;
	pol.y = 500;
	PtArg_t numeric_level[4];
	PtSetArg(&numeric_level[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&numeric_level[1], Pt_ARG_NUMERIC_MAX, MAXIMUMLEVEL,0);
	PtSetArg(&numeric_level[2], Pt_ARG_NUMERIC_MIN, MINIMUMLEVEL,0);	
	PtSetArg(&numeric_level[3], Pt_ARG_NUMERIC_VALUE, DEFAULTVALUE,0);
	PtSetArg(&numeric_level[4], Pt_CB_NUMERIC_CHANGED, callbacklevel,
		sizeof(callbacklevel)/sizeof(callbacklevel[0]));	
	
	PtWidget_t *numeric = PtCreateWidget(PtNumericInteger, airport_weather, 5, numeric_level);
	
	Zdarzenia::getInstance().put_level(DEFAULTVALUE);	
	cout << "Ustawiono domyslny stopien na: " << Zdarzenia::getInstance().get_level() <<endl;
	
	PtArg_t arg_label_level[4];
	pol.x -= 115;
	pol.y += 5;
	dim.h=20;
	PtSetArg(&arg_label_level[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_label_level[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_label_level[2], Pt_ARG_TEXT_STRING,"Stopien pogody: ",0);
	PtWidget_t *label_level = PtCreateWidget(PtLabel, airport_weather, 4, arg_label_level);
    
//	koniec obslugi wyboru poziomu awarii



	const char * constlist[50];
	int i=0;
	
	vector<lotnisko> tmp = Zdarzenia::getInstance().get_lotniska();
	for(vector<lotnisko>::iterator it=tmp.begin(); it < tmp.end(); it++) {
		constlist[i++] = (it->nazwa).c_str();
	}
	PtListAddItems(list_airport, constlist, i, 0);
	
	PtRealizeWidget(airport_weather);
}

// oblsuga przycisku znajdujacego sie na oknie dodawania awarii lotniska
int GUI::push_button_airport_add_weather(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{
		Zdarzenia::getInstance().dodaj_awarie_pogody();
		cout << "dodaje pogode" <<endl;
		Zdarzenia::getInstance().put_weather("null");
		cout << "pogoda wyczyszczone "<<Zdarzenia::getInstance().get_weather()<<endl;
		Zdarzenia::getInstance().put_airport_from("null");	
		cout<< "lotnisko wyczyszczone " << Zdarzenia::getInstance().get_airport_from()<<endl;
}

//obsluga listy lotnisko
int GUI::push_list_airport_add_weather_airport(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{	
	PtListDeleteAllItems( (PtWidget_t *)  data);
	Zdarzenia::getInstance().put_weather("null");
	cout << Zdarzenia::getInstance().get_weather()<<endl;
	Zdarzenia::getInstance().put_airport_from(((PtListCallback_t *)(cbinfo->cbdata))->item);	
	cout<< "lotnisko " << Zdarzenia::getInstance().get_airport_from()<<endl;
	const char* constlist[50];
	int i = 0;
	//lista_awarii tmp = Zdarzenia::getInstance().get_samolot_awarie(((PtListCallback_t *)(cbinfo->cbdata))->item);
	
	//bedzie
	//	lista_awarii tmp = Zdarzenia::getInstance().get_lotnisko_mozliwe_pogody(((PtListCallback_t *)(cbinfo->cbdata))->item);
	//koniec
	
	//for(vector<zdarzenie>::iterator it=tmp.awaria.begin(); it < tmp.awaria.end(); it++) {
	//	constlist[i++] = (it->nazwa_zdarzenia).c_str();
	//}
	vector<zdarzenie> zdarzenia = Zdarzenia::getInstance().mozliwe_awarie_pogody();	
	//bedzie
	//	lista_awarii tmp = Zdarzenia::getInstance().get_lotnisko_mozliwe_awarie(((PtListCallback_t *)(cbinfo->cbdata))->item);
	//koniec
	for(vector<zdarzenie>::iterator it=zdarzenia.begin(); it < zdarzenia.end(); it++) {
		constlist[i++] = (it->nazwa).c_str();
	}
	//tymczasowe dopoki nie ma danych
//	constlist[i++]="deszcz";
//	constlist[i++]="tornado";
	//koniec tymczasowe
	
	PtListAddItems((PtWidget_t *)  data, constlist, i, 0);
}

//obsluga listy pogody
int GUI::push_list_airport_add_weather_weather(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{
	Zdarzenia::getInstance().put_weather(((PtListCallback_t *)(cbinfo->cbdata))->item);	
	cout<< "pogoda lotniska " << Zdarzenia::getInstance().get_weather()<<endl;
}




// koniec obslugi okna dodawania pogody




//obsluga okna dodawania awarii do samolotu





// obsluga przycisku dodawania awarii do samolotu
int GUI::push_button_airplane(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{	
	PtWidget_t *airplane_event = PtCreateWidget(PtWindow, NULL, 0, NULL);
		
	int (*airplane_add_event) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=
				&push_button_airplane_add_event;
	PtCallback_t callbackairplaneadd[]= {{airplane_add_event, NULL}};
	
	PhPoint_t posb1 = { 300, 600};
	PtArg_t arg_bs1[4];	
	PtSetArg( &arg_bs1[0], Pt_ARG_POS, &posb1, 0 );
	PtSetArg( &arg_bs1[1], Pt_ARG_COLOR, Pg_BLACK, 0 );
	PtSetArg( &arg_bs1[2], Pt_ARG_TEXT_STRING, "DODAJ AWARIE", 0 );
	PtSetArg(&arg_bs1[3], Pt_CB_ACTIVATE, callbackairplaneadd,
 	      sizeof(callbackairplaneadd)/sizeof(callbackairplaneadd[0]));	
	PtWidget_t *but = PtCreateWidget(PtButton, airplane_event, 4, arg_bs1);	
	
	PhDim_t dim;
	PhPoint_t pol;
	
	PtArg_t arg_list_airplane[4];	
	pol.x = 1;
	pol.y = 50;
	dim.h = 400;
	dim.w = 200;
	PtSetArg(&arg_list_airplane[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_list_airplane[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_list_airplane[2], Pt_ARG_SELECTION_MODE,Pt_SINGLE_MODE, 0);
	PtWidget_t *list_airplane = PtCreateWidget(PtList, airplane_event, 4, arg_list_airplane);
	PtArg_t arg_label_airplane[4];
	pol.y-=20;
	dim.h=20;
	PtSetArg(&arg_label_airplane[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_label_airplane[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_label_airplane[2], Pt_ARG_TEXT_STRING,"Samolot",0);
	PtWidget_t *label_airplane = PtCreateWidget(PtLabel, airplane_event, 4, arg_label_airplane);
	
	// lista zdarzen na lotniskach
	
     PtArg_t arg_list_airplane_events[4];	
	pol.x+= 203;
	pol.y = 50;
	dim.h = 400;
	dim.w = 200;
	PtSetArg(&arg_list_airplane_events[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_list_airplane_events[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_list_airplane_events[2], Pt_ARG_SELECTION_MODE,Pt_SINGLE_MODE, 0);
	PtWidget_t *list_airplane_events = PtCreateWidget(PtList, airplane_event, 4, arg_list_airplane_events);
	PtArg_t arg_label_airplane_events[4];
	pol.y -= 20;
	dim.h=20;
	PtSetArg(&arg_label_airplane_events[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_label_airplane_events[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_label_airplane_events[2], Pt_ARG_TEXT_STRING,"awaria",0);
	PtWidget_t *label_airplane_events = PtCreateWidget(PtLabel, airplane_event, 4, arg_label_airplane_events);
    
	int (*f) (PtWidget_t *a, void *b,PtCallbackInfo_t *c)=&push_list_airplane_add_event_airplane;
	PtAddCallback(list_airplane, Pt_CB_SELECTION,f, list_airplane_events);
	
	int (*f2) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=&push_list_airplane_add_event_event;
	PtAddCallback(list_airplane_events, Pt_CB_SELECTION, f2, list_airplane);


	// obsluga wyboru poziomu awarii


	int (*level) (PtWidget_t *a, void *b, PtCallbackInfo_t *c)=&push_numeric_level;
	PtCallback_t callbacklevel[]= {{level, NULL}};

	pol.x =220;
	pol.y = 500;
	PtArg_t numeric_level[4];
	PtSetArg(&numeric_level[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&numeric_level[1], Pt_ARG_NUMERIC_MAX, MAXIMUMLEVEL,0);
	PtSetArg(&numeric_level[2], Pt_ARG_NUMERIC_MIN, MINIMUMLEVEL,0);	
	PtSetArg(&numeric_level[3], Pt_ARG_NUMERIC_VALUE, DEFAULTVALUE,0);
	PtSetArg(&numeric_level[4], Pt_CB_NUMERIC_CHANGED, callbacklevel,
		sizeof(callbacklevel)/sizeof(callbacklevel[0]));	
	
	PtWidget_t *numeric = PtCreateWidget(PtNumericInteger, airplane_event, 5, numeric_level);
	
	Zdarzenia::getInstance().put_level(DEFAULTVALUE);	
	cout << "Ustawiono domyslny stopien na: " << Zdarzenia::getInstance().get_level() <<endl;
	
	PtArg_t arg_label_level[4];
	pol.x -= 100;
	pol.y += 5;
	dim.h=20;
	PtSetArg(&arg_label_level[0], Pt_ARG_POS, &pol, 0);
	PtSetArg(&arg_label_level[1], Pt_ARG_DIM, &dim, 0);
	PtSetArg(&arg_label_level[2], Pt_ARG_TEXT_STRING,"Stopien awarii: ",0);
	PtWidget_t *label_level = PtCreateWidget(PtLabel, airplane_event, 4, arg_label_level);
    
//	koniec obslugi wyboru poziomu awarii
	PtListDeleteAllItems(list_airplane);
    char k1[20];
    const char *k2;
    string k3, tmp2;
    vector<samolot_polozenie> tmp = Zdarzenia::getInstance().get_aktywne_samoloty();
 //  int i=0;
 	const char* constlist[50];
    for(vector<samolot_polozenie>::iterator it=tmp.begin(); it < tmp.end(); it++) {
            k2 = itoa(it->id_samolotu,k1,10);
            tmp2 = k2;
         	  k3=tmp2 + (it->nazwa_samolotu);
            k2=k3.c_str();
            constlist[0]=k2;
            PtListAddItems(list_airplane, constlist,1, 0);
    }
    PtRealizeWidget(airplane_event);
}

int GUI::push_button_airplane_add_event(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{
		Zdarzenia::getInstance().dodaj_awarie_samolotu();
		cout << "dodaje awarie" <<endl;
		Zdarzenia::getInstance().put_event("null");
		cout <<"awaria wyczyszczone"<< Zdarzenia::getInstance().get_event()<<endl;
		Zdarzenia::getInstance().put_airplane_id(-1);	
		cout<< "id samolotu wyczyszczone " << Zdarzenia::getInstance().get_airplane_id()<<endl;
		Zdarzenia::getInstance().put_airplane("null");	
		cout<< "nazwa samolotu wyczyszczone " << Zdarzenia::getInstance().get_airplane()<<endl;
}

int GUI::push_list_airplane_add_event_airplane(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{
	PtListDeleteAllItems( (PtWidget_t *)  data);
	Zdarzenia::getInstance().put_event("null");
	cout << Zdarzenia::getInstance().get_event()<<endl;
	int id=-1;
	vector<samolot_polozenie> tmp2 = Zdarzenia::getInstance().get_aktywne_samoloty();
	for(vector<samolot_polozenie>::iterator it=tmp2.begin(); it < tmp2.end(); it++) {
		    char k1[20];
    		const char *k2;
    		string k3, tmp2;
            k2 = itoa(it->id_samolotu,k1,10);
            tmp2 = k2;
         	  k3=tmp2 + (it->nazwa_samolotu);
            k2=k3.c_str();
		if (!strcmp(((PtListCallback_t *)(cbinfo->cbdata))->item,k2))
		{
			id = it->id_samolotu;
			cout << "id samolotu: "<< it->id_samolotu << endl;
		 	break;
		}
	}
	
	
	Zdarzenia::getInstance().put_airplane_id(id);	
	cout<< "id samolotu " << Zdarzenia::getInstance().get_airplane_id()<<endl;
	
	Zdarzenia::getInstance().put_airplane(((PtListCallback_t *)(cbinfo->cbdata))->item);	
	cout<< "samolot " << Zdarzenia::getInstance().get_airplane()<<endl;

	const char* constlist[50];
	int i = 0;
	vector<zdarzenie> zdarzenia = Zdarzenia::getInstance().mozliwe_awarie_samolot();	
	for(vector<zdarzenie>::iterator it=zdarzenia.begin(); it < zdarzenia.end(); it++) {
		constlist[i++] = (it->nazwa).c_str();
	}
	PtListAddItems((PtWidget_t *)  data, constlist, i, 0);
}

int GUI::push_list_airplane_add_event_event(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{
	Zdarzenia::getInstance().put_airplane_event(((PtListCallback_t *)(cbinfo->cbdata))->item);	
	cout<< "awaria samolotu " << Zdarzenia::getInstance().get_airplane_event()<<endl;
}

// koniec obslugi okna dodawania awarii do samolotu




// obsluga tymczasowa

//tmp
//aktualizacja

int GUI::push_button_actualize(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{
	//PtListDeleteAllItems( (PtWidget_t *)  data);
	const char* constlist[50];
	int i =0;
	cout << "aktualizuje liste samolotow"<<endl;
//	cout << "dobrze"<<endl;
//			vector<samolot> tmp = Zdarzenia::getInstance().get_samoloty();
//			for(vector<samolot>::iterator it=tmp.begin(); it < tmp.end(); it++) {
//				constlist[i++] = (it->nazwa).c_str();
//			}
	PtListAddItems((PtWidget_t *)  data, constlist, i, 0);
}
/*
int GUI::push_list_airplane_act(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{
	PtListDeleteAllItems( (PtWidget_t *)  data);
	const char* constlist[50];
	int i =0;
	cout << "aktualizuje"<<endl;
	cout << "dobrze"<<endl;
	
	
	//vector<samolot> tmp = Zdarzenia::getInstance().get_samoloty();
	//for(vector<samolot>::iterator it=tmp.begin(); it < tmp.end(); it++) {
	//	constlist[i++] = (it->nazwa).c_str();
	//}
	
	vector<samolot_polozenie> tmp = Zdarzenia::getInstance().get_aktywne_samoloty();
	for(vector<samolot_polozenie>::iterator it=tmp.begin(); it < tmp.end(); it++) {
		constlist[i++] = (it->nazwa_samolotu).c_str();
	}
	PtListAddItems((PtWidget_t *)  data, constlist, i, 0);

} 
*/
int GUI::push_list_airplane_act(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{
    PtListDeleteAllItems( (PtWidget_t *)  data);
    const char* constlist[50];
    int i =0;
    cout << "aktualizuje liste samolotow"<<endl;
    //cout << "dobrze"<<endl;
    
    /*
    vector<samolot> tmp = Zdarzenia::getInstance().get_samoloty();
    for(vector<samolot>::iterator it=tmp.begin(); it < tmp.end(); it++) {
        constlist[i++] = (it->nazwa).c_str();
    }
    */
    char k1[20];
    const char *k2;
    string k3, tmp2;
    vector<samolot_polozenie> tmp = Zdarzenia::getInstance().get_aktywne_samoloty();
    i=0;
    for(vector<samolot_polozenie>::iterator it=tmp.begin(); it < tmp.end(); it++) {
            k2 = itoa(it->id_samolotu,k1,10);
            tmp2 = k2;
         	  k3=tmp2 + (it->nazwa_samolotu);
            k2=k3.c_str();
            constlist[0]=k2;
            PtListAddItems((PtWidget_t *)  data, constlist,1, 0);
    }
    cout << "constlist"<<endl;
    for (int j=0;j<i;j++)
      cout << constlist[j]<<endl;
    
}





int fill_airplane_list(PtWidget_t *list_airplane)
{
//	PtWidget_t *list_airplane = GUI::get_list_airplane();
	PtListDeleteAllItems(list_airplane);
//	const char* constlist[50];
//	int i;	
//	vector<samolot_polozenie> tmp = Zdarzenia::getInstance().get_aktywne_samoloty();
//	for(vector<samolot_polozenie>::iterator it=tmp.begin(); it < tmp.end(); it++) {
//		constlist[i++] = ((it->nazwa_samolotu)).c_str();
//	}
//	PtListAddItems(list_airplane, constlist, i, 0);
}


int GUI::push_numeric_level(PtWidget_t *w, void *data,
               PtCallbackInfo_t *cbinfo)
{
	cout << "dodaje poziom: ";
	Zdarzenia::getInstance().put_level(((PtNumericIntegerCallback_t *)(cbinfo->cbdata))->numeric_value);	
	cout <<	Zdarzenia::getInstance().get_level() <<endl;
}



